/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package editor.impl;

import editor.EditorPackage;
import editor.Element;
import editor.Root;
import editor.RootRelationship;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Root Relationship</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link editor.impl.RootRelationshipImpl#getSourceRoot <em>Source Root</em>}</li>
 *   <li>{@link editor.impl.RootRelationshipImpl#getTargetRoot <em>Target Root</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class RootRelationshipImpl extends EObjectImpl implements RootRelationship {
	/**
   * The cached value of the '{@link #getSourceRoot() <em>Source Root</em>}' reference.
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @see #getSourceRoot()
   * @generated
   * @ordered
   */
	protected Root sourceRoot;

	/**
   * The cached value of the '{@link #getTargetRoot() <em>Target Root</em>}' reference.
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @see #getTargetRoot()
   * @generated
   * @ordered
   */
	protected Element targetRoot;

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	protected RootRelationshipImpl() {
    super();
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	protected EClass eStaticClass() {
    return EditorPackage.Literals.ROOT_RELATIONSHIP;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public Root getSourceRoot() {
    if (sourceRoot != null && sourceRoot.eIsProxy())
    {
      InternalEObject oldSourceRoot = (InternalEObject)sourceRoot;
      sourceRoot = (Root)eResolveProxy(oldSourceRoot);
      if (sourceRoot != oldSourceRoot)
      {
        if (eNotificationRequired())
          eNotify(new ENotificationImpl(this, Notification.RESOLVE, EditorPackage.ROOT_RELATIONSHIP__SOURCE_ROOT, oldSourceRoot, sourceRoot));
      }
    }
    return sourceRoot;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public Root basicGetSourceRoot() {
    return sourceRoot;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public NotificationChain basicSetSourceRoot(Root newSourceRoot, NotificationChain msgs) {
    Root oldSourceRoot = sourceRoot;
    sourceRoot = newSourceRoot;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, EditorPackage.ROOT_RELATIONSHIP__SOURCE_ROOT, oldSourceRoot, newSourceRoot);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public void setSourceRoot(Root newSourceRoot) {
    if (newSourceRoot != sourceRoot)
    {
      NotificationChain msgs = null;
      if (sourceRoot != null)
        msgs = ((InternalEObject)sourceRoot).eInverseRemove(this, EditorPackage.ROOT__OUTGOING_ROOT, Root.class, msgs);
      if (newSourceRoot != null)
        msgs = ((InternalEObject)newSourceRoot).eInverseAdd(this, EditorPackage.ROOT__OUTGOING_ROOT, Root.class, msgs);
      msgs = basicSetSourceRoot(newSourceRoot, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, EditorPackage.ROOT_RELATIONSHIP__SOURCE_ROOT, newSourceRoot, newSourceRoot));
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public Element getTargetRoot() {
    if (targetRoot != null && targetRoot.eIsProxy())
    {
      InternalEObject oldTargetRoot = (InternalEObject)targetRoot;
      targetRoot = (Element)eResolveProxy(oldTargetRoot);
      if (targetRoot != oldTargetRoot)
      {
        if (eNotificationRequired())
          eNotify(new ENotificationImpl(this, Notification.RESOLVE, EditorPackage.ROOT_RELATIONSHIP__TARGET_ROOT, oldTargetRoot, targetRoot));
      }
    }
    return targetRoot;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public Element basicGetTargetRoot() {
    return targetRoot;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public NotificationChain basicSetTargetRoot(Element newTargetRoot, NotificationChain msgs) {
    Element oldTargetRoot = targetRoot;
    targetRoot = newTargetRoot;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, EditorPackage.ROOT_RELATIONSHIP__TARGET_ROOT, oldTargetRoot, newTargetRoot);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public void setTargetRoot(Element newTargetRoot) {
    if (newTargetRoot != targetRoot)
    {
      NotificationChain msgs = null;
      if (targetRoot != null)
        msgs = ((InternalEObject)targetRoot).eInverseRemove(this, EditorPackage.ELEMENT__INCOMING_COMPLEX_ELEMENT, Element.class, msgs);
      if (newTargetRoot != null)
        msgs = ((InternalEObject)newTargetRoot).eInverseAdd(this, EditorPackage.ELEMENT__INCOMING_COMPLEX_ELEMENT, Element.class, msgs);
      msgs = basicSetTargetRoot(newTargetRoot, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, EditorPackage.ROOT_RELATIONSHIP__TARGET_ROOT, newTargetRoot, newTargetRoot));
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
    switch (featureID)
    {
      case EditorPackage.ROOT_RELATIONSHIP__SOURCE_ROOT:
        if (sourceRoot != null)
          msgs = ((InternalEObject)sourceRoot).eInverseRemove(this, EditorPackage.ROOT__OUTGOING_ROOT, Root.class, msgs);
        return basicSetSourceRoot((Root)otherEnd, msgs);
      case EditorPackage.ROOT_RELATIONSHIP__TARGET_ROOT:
        if (targetRoot != null)
          msgs = ((InternalEObject)targetRoot).eInverseRemove(this, EditorPackage.ELEMENT__INCOMING_COMPLEX_ELEMENT, Element.class, msgs);
        return basicSetTargetRoot((Element)otherEnd, msgs);
    }
    return super.eInverseAdd(otherEnd, featureID, msgs);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
    switch (featureID)
    {
      case EditorPackage.ROOT_RELATIONSHIP__SOURCE_ROOT:
        return basicSetSourceRoot(null, msgs);
      case EditorPackage.ROOT_RELATIONSHIP__TARGET_ROOT:
        return basicSetTargetRoot(null, msgs);
    }
    return super.eInverseRemove(otherEnd, featureID, msgs);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
    switch (featureID)
    {
      case EditorPackage.ROOT_RELATIONSHIP__SOURCE_ROOT:
        if (resolve) return getSourceRoot();
        return basicGetSourceRoot();
      case EditorPackage.ROOT_RELATIONSHIP__TARGET_ROOT:
        if (resolve) return getTargetRoot();
        return basicGetTargetRoot();
    }
    return super.eGet(featureID, resolve, coreType);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public void eSet(int featureID, Object newValue) {
    switch (featureID)
    {
      case EditorPackage.ROOT_RELATIONSHIP__SOURCE_ROOT:
        setSourceRoot((Root)newValue);
        return;
      case EditorPackage.ROOT_RELATIONSHIP__TARGET_ROOT:
        setTargetRoot((Element)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public void eUnset(int featureID) {
    switch (featureID)
    {
      case EditorPackage.ROOT_RELATIONSHIP__SOURCE_ROOT:
        setSourceRoot((Root)null);
        return;
      case EditorPackage.ROOT_RELATIONSHIP__TARGET_ROOT:
        setTargetRoot((Element)null);
        return;
    }
    super.eUnset(featureID);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public boolean eIsSet(int featureID) {
    switch (featureID)
    {
      case EditorPackage.ROOT_RELATIONSHIP__SOURCE_ROOT:
        return sourceRoot != null;
      case EditorPackage.ROOT_RELATIONSHIP__TARGET_ROOT:
        return targetRoot != null;
    }
    return super.eIsSet(featureID);
  }

} //RootRelationshipImpl
